package DFS;

import java.util.*;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:TQ02
 * Data:2024-03-20
 * Time:16:31
 * Text：46. 全排列
 */
public class Text5 {
    List<List<Integer>> t1=new ArrayList<>();
    List<Integer> path;
    boolean[] check;
    void dfs(int[] nums){
        if(nums.length==path.size()){
            t1.add(new ArrayList<>(path));
        }
        for(int i=0;i<nums.length;i++){
            if(!check[i]){
                path.add(nums[i]);
                check[i]=true;
                dfs(nums);
                //恢复现场
                check[i]=false;
                path.remove(path.size()-1);
            }
        }
    }

    public List<List<Integer>> permute(int[] nums) {
        check=new boolean[nums.length];
        path=new ArrayList<>();
        dfs(nums);
        return t1;
    }

    public static void main(String[] args) {
        Text5 t1=new Text5();
        int[] array={1,2,3};
        t1.permute(array);
    }
}
